package com.hz.ruoyistorage.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hz.rouyigonggong.domain.basedomain.BaseDomain;
import com.hz.rouyigonggong.utils.ResultJSON;
import com.hz.ruoyistorage.domain.LgColdStorage;
import com.hz.ruoyistorage.domain.LgColdType;
import com.hz.ruoyistorage.domain.LgGoods;
import com.hz.ruoyistorage.mapper.LgColdTypeMapper;
import com.hz.ruoyistorage.service.LgColdTypeService;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * @version 1.0
 * @Author gj
 * @Date 2025/3/10 10:22
 * @注释
 */
@RestController
@RequestMapping("/storagePrice")
public class LgColdTypeController {
    @Autowired
    private LgColdTypeService lgColdTypeService;
    @Autowired
    private LgColdTypeMapper lgColdTypeMapper;
    private Map<String,Object> query2;



//    @RequiresPermissions("storage:storagePrice:getAll")
    @GetMapping("/getColdTypeList")
    public ResultJSON getColdTypeList(){
        return ResultJSON.success(lgColdTypeService.list(null));
    }


//    @PostMapping("/getAll")
//    public ResultJSON getAll(String pageNum,String pageSize){
//        return ResultJSON.success(lgColdTypeService.list());
//    }
//@RequiresPermissions("storage:storagePrice:getAll")
    @PostMapping("/getAll")
    public ResultJSON getAll(@RequestBody Map<String,Object> query){
        query2 = query;
        query.put("createBy",String.valueOf(BaseDomain.getUserId()));
        return ResultJSON.success(lgColdTypeService.getAll(query));
    }
    //获得数据条数
//    @RequiresPermissions("storage:storagePrice:getAll")
    @PostMapping("/getTotal")
    public ResultJSON getTotal(@RequestBody Map<String,Object> query){
        query2 = query;
        query.put("createBy",String.valueOf(BaseDomain.getUserId()));
        return ResultJSON.success(lgColdTypeService.getCount(query));
    }
    //新增
//    @RequiresPermissions("storage:storagePrice:add")
    @PostMapping("/addColdType")
    public ResultJSON addColdType(@RequestBody LgColdType lgColdType){
        lgColdType.setCreateBy(String.valueOf(BaseDomain.getUserId()));
        return ResultJSON.success(lgColdTypeService.save(lgColdType));
    }
    //修改
//    @RequiresPermissions("storage:storagePrice:update")
    @PostMapping("/updateColdType")
    public ResultJSON updateColdType(@RequestBody LgColdType lgColdType){
        return ResultJSON.success(lgColdTypeService.updateById(lgColdType));
    }
    //获得单个
//    @RequiresPermissions("storage:storagePrice:getAll")
    @GetMapping(value = "/{coldTypeId}")
    public ResultJSON getColdTypeById(@PathVariable Integer coldTypeId){
        return ResultJSON.success(lgColdTypeService.getById(coldTypeId));
    }
    //逻辑删除
    //逻辑删除
//    @RequiresPermissions("storage:storagePrice:delete")
    @PostMapping(value = "/{coldTypeIds}")
    public ResultJSON deleteBigCold(@PathVariable Long[] coldTypeIds){
        for (Long coldTypeId : coldTypeIds){
//            lgColdTypeService.removeById(coldTypeId);
            lgColdTypeMapper.deleteById(coldTypeId);
        }
        return ResultJSON.success();
    }

    //导出
    @RequiresPermissions("storage:storagePrice:export")
    @Log(title = "冷库类型管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LgColdType lgColdType)
    {

        List<LgColdType> list = lgColdTypeService.list(null);
        ExcelUtil<LgColdType> util = new ExcelUtil<LgColdType>(LgColdType.class);
        util.exportExcel(response, list, "冷库类型管理");
    }

}
